<?php
    echo elgg_view('thewire/forms/add');
	 global $CONFIG;
	 $ajax_url = $vars['url'].'mod/'.RIVER_WIRE_NAME.'/endpoint/get_river_item.php';
?>

<script type="text/javascript">
	function hideRiverMessage() {
		$('.river-success-msg').fadeOut('slow');
	}


    $('form[name=noteForm]').submit(function(e) {

		var $form = $(this);
		var data = $form.serialize();
		var url = $form.attr('action');

		$.post(url, data,function(info){
			if (info.error) {
				alert(info.error); //cambiarlo por un mensaje mas lindo
			}
			else {
				$('#thewire_large-textarea').val('');
				$('#river_item_list').append(info.html);

				$.get("<?php echo $ajax_url ?>",{ guid: info.guid } , function(river_item){
					$('.river_item_list').prepend(river_item);
					$('.thewire_characters_remaining_field').val(140);
					$('form[name=noteForm]').prepend('<span class="river-success-msg">'+info.success+'</span>');
					$('.river-success-msg').css("color","green");

					setTimeout('hideRiverMessage()', 3000);
				});

			}
		  }, "json");

		e.preventDefault()
      return false;
    });
</script>